//
//  CommunityManageViewController.m
//  QRMaster
//
//  Created by liuyunlong on 15/11/10.
//  Copyright © 2015年 myApple. All rights reserved.
//

#import "CommunityManageViewController.h"
#import "RequestNetWork.h"
#import "Reachability.h"
#import "PromptInfoView.h"
#import "selectCommunityController.h"
#import "OpertionPlist.h"
#import "GuestCommunitySelectViewController.h"
#import "QRSingleton.h"
#import "StaffManagerViewController.h"
#import "GuestManagerViewController.h"
#import "EditAfterAddViewController.h"
#import "EditAfterAddGuestViewController.h"
#import "CommunityListModel.h"
#import "SetLockViewController.h"
#import "GetNameByID.h"
#import "BackTableViewCell.h"
#import "DatePickerViewController.h"
#import "ManagerShareCardController.h"
#import "checkPower.h"
#import "CustomerSearchViewController.h"
#import "setLockPwdViewController.h"
#import "ManageBaseVC.h"
#import "ManageGuestVC.h"
#import "ManageStaffVC.h"
#import "MangeCommunityVC.h"
#import "AppDelegate.h"

@interface CommunityManageViewController ()<UIAlertViewDelegate,UIActionSheetDelegate,UIScrollViewDelegate,ManageStaffVCDelegate,UISearchBarDelegate,ManageGuestVCDelegate,UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate>
{
    UIView * indexBackGroundView;
    float offSetX;//indexBackGroundView滑行的距离
    UIScrollView * MainScrollerView;
    UIButton * communitySelectBtn;//浮动的选择集群的按钮
    UIView  * titleView ;//不是删除状态情况下的导航栏
    UIView * deleteTitleView;//删除状态情况下的导航栏
    UILabel * deleteCountLabel;//现实删除cell的个数
    UIScrollView * upScrollerView;//上面三个滚动按钮;
    UIButton * addBtn;
    UIImageView * searchImgView;//显示的搜索按钮，没有点击之前
    UIButton * nameSearchBtn;
    UISearchBar * nameSearchBar;//搜索框
    UIImageView * cancelImgView;//取消搜索的点击事件
    NSMutableDictionary * searchContentDict;//通知发送搜索内容
    
    UIView * NetWorkBreakView;//断网时显示的view
    
    NSString * groupId;//组的ID
    NSString * communityRole ;//在集群的角色
    NSString * communityID;
    
    NSMutableDictionary * communityIdDict;//当集群改变时传递的communityid号
    
    //客户管理切换房间的时候需要
    NSString * bulidingId;
    NSString * floorId;
    NSString * roomId;
    
    //显示客户信息的自标题
    NSString * bulidingName;
    NSString * floorName;
    NSString * roomName;
    
    NSMutableDictionary * HouseDict;//发送通知告诉客户请求新的房间人员数据
    
    int nowContentOffX;//当前所处的是职员还是客户还是物业页面
    
    NSArray * bulidingArray;//楼栋的信息（存plist文件的）
    
    GetNameByID * getName;//通过ID来找出楼栋的中文名字
    
    QRSingleton * singleton;//单例  保存集群ID号
    
    NSArray * communityArray;
    
    UIImageView * quickImgView ;//快捷二维码键
    UIImageView * changeCommunityImgView;//切换集群
    UIButton * upScrollerBtn;//点击切换页面
    
    UITableView * backTabelView;
    NSArray * backChooseArray;
    NSArray * backChooseImgArray;
    UIImageView * allBackImgView;//点击加号是遮住整个view的透明的遮罩层
    CGRect backTabelViewFrame;
    UIImageView * promtNoCommunityView;
    
    UILabel * communityNameLabel;//集群
    UILabel * allNameLabel;//集群到房间的名字
    UIView * nameLabelView;
    UIActivityIndicatorView * _activityIndicator;
    
    //多语言
    UILabel * cancelSearchLabel;
    UILabel * promtLable;
    UILabel * promtGroupManagerLable;
    UILabel * netWorkBreakLabel;
    UILabel * promtLabel;
    NSArray * nameArray;
    
    UIScrollView * mainContentScrollerView;
    UIScrollView * smallScrollerView;
    ManageBaseVC * bvc;
    NSInteger flag;
}

@end

@implementation CommunityManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    flag = 1;
    singleton = [QRSingleton sharedQRSingleton];
    getName = [[GetNameByID alloc]init];
    getName = [GetNameByID shareGetNameByID];
    nowContentOffX = 0;
    communityArray = [[NSArray alloc]init];
    backChooseImgArray = @[@"ic_change20",@"ic_eye20",@"ic_txl"];
    bulidingId = @"";
    floorId = @"";
    roomId = @"";
    bvc = [[ManageBaseVC alloc]init];
    self.view.backgroundColor = [UIColor whiteColor];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeHeight) name:@"showCommunityName" object:nil];
    [self prepareTitleView];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(netWorkBreak:) name:@"netWorkBreak" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(JoinNetWork:) name:@"netWorkJion" object:nil];
    communityID = singleton.communityId;
    [self prepareCommunityData];
    searchContentDict = [[NSMutableDictionary alloc]init];
    communityIdDict = [[NSMutableDictionary alloc]init];
    HouseDict = [[NSMutableDictionary alloc]init];
    
    ManageStaffVC * smv = [[ManageStaffVC alloc]init];
    [self addChildViewController:smv];
    ManageGuestVC * gmv = [[ManageGuestVC alloc]init];
    [self addChildViewController:gmv];
    MangeCommunityVC * cmv = [[MangeCommunityVC alloc]init];
    [self addChildViewController:cmv];
    singleton.managementIndex = 0;
    float x = 0;
    float y = 80;
    float width = [UIScreen mainScreen].bounds.size.width;
    float height = [UIScreen mainScreen].bounds.size.height;
    CGFloat  contentX = self.childViewControllers.count * [UIScreen mainScreen].bounds.size.width;
    mainContentScrollerView = [[UIScrollView alloc]initWithFrame:CGRectMake(x,y,width,height)];
    mainContentScrollerView.contentSize = CGSizeMake(contentX, 0);
    mainContentScrollerView.pagingEnabled = YES;
    [self.view addSubview:mainContentScrollerView];
    mainContentScrollerView.delegate = self;
    mainContentScrollerView.showsHorizontalScrollIndicator = NO;
    mainContentScrollerView.bounces = NO;
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //7.1以及以下的系统内存较少只能这里加载view，不然会黑屏
    if (flag == 1) {
        UIViewController * newVC = [self.childViewControllers firstObject];
        newVC.view.frame = mainContentScrollerView.bounds;
        [mainContentScrollerView addSubview:newVC.view];
        flag = 2;
    }
    nameArray = @[NSLocalizedString(@"staff", nil),NSLocalizedString(@"guest", nil),NSLocalizedString(@"property", nil)];
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"changeCommunity"]isEqualToString:@"yes"]) {
        [self tellUserUseAppPromtView];
    }
    if (singleton.managementIndex == 2) {
        communityNameLabel.text = singleton.communityName;
    }
    else if(singleton.managementIndex == 1)
    {
        communityNameLabel.text = [NSString stringWithFormat:@"%@%@%@%@", singleton.communityName,singleton.buildingName,singleton.floorName,singleton.roomName];
    }
    else
    {
        communityNameLabel.text = singleton.communityName;
    }
    promtLable.text = NSLocalizedString(@"deleteOrNot", nil);
    promtGroupManagerLable.text = NSLocalizedString(@"deleteGroupManager", nil);
    promtLabel.text = NSLocalizedString(@"addCommunityRefresh", nil);
    for (int i = 0 ; i < nameArray.count; i ++) {
        UIButton * upBtn = (UIButton *)[self.view viewWithTag:500 + i];
        [upBtn setTitle:nameArray[i] forState:0];
    }
}


-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    [self scrollViewWillBeginDragging:scrollView];
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    if (scrollView == mainContentScrollerView) {
        NSInteger index = scrollView.contentOffset.x / mainContentScrollerView.frame.size.width;
        bvc = self.childViewControllers[index];
        [bvc hiddenVc:index];
    }
}

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
    if (scrollView == mainContentScrollerView) {
        
        singleton.managementIndex = scrollView.contentOffset.x / mainContentScrollerView.frame.size.width;
        bvc = self.childViewControllers[singleton.managementIndex];
        [bvc showVc:singleton.managementIndex];
        if (singleton.managementIndex == 1) {
            communityNameLabel.text =[NSString stringWithFormat:@"%@%@%@%@", singleton.communityName,singleton.buildingName,singleton.floorName,singleton.roomName];
        }
        else
        {
            communityNameLabel.text = singleton.communityName;
        }
        if (bvc.view.superview) {
            return;
        }
        bvc.view.frame = mainContentScrollerView.bounds;
        [mainContentScrollerView addSubview:bvc.view];
    }
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [self scrollViewDidEndScrollingAnimation:mainContentScrollerView];
}


-(void)prepareTitleView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    float x = ScreenWidth - 40;
    float y = 2;
    float width = 40;
    float height = 40;
    
    //断网时候出现的提示
    x = 0;
    y = 0;
    width = ScreenWidth;
    height = 40;
    NetWorkBreakView = [[UIView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    NetWorkBreakView.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:242 /255.0 blue:187 /255.0 alpha:1];
    NetWorkBreakView.hidden = YES;
    [self.view addSubview:NetWorkBreakView];
    
    x = 0;
    y = 10;
    width = ScreenWidth;
    height = 20;
    netWorkBreakLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    netWorkBreakLabel.text = NSLocalizedString(@"managerNoNetWork", nil);
    netWorkBreakLabel.textAlignment = NSTextAlignmentCenter;
    netWorkBreakLabel.font = [UIFont systemFontOfSize:14.0];
    [NetWorkBreakView addSubview:netWorkBreakLabel];
    
    x = 0;
    y = 0;//网络判断中给他加了起始高度
    width = ScreenWidth;
    height = 40;
    nameLabelView = [[UIView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    nameLabelView.backgroundColor = RGBA(255, 255, 204, 1);
    [self.view addSubview:nameLabelView];
    x = 40;
    y = 0;
    width = ScreenWidth - 80;
    communityNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    communityNameLabel.text = NSLocalizedString(@"noCommunity", nil);
    communityNameLabel.numberOfLines = 2;
    communityNameLabel.font = [UIFont systemFontOfSize:14.0];
    communityNameLabel.textColor = [UIColor blackColor];
    communityNameLabel.textAlignment = NSTextAlignmentCenter;
    [nameLabelView addSubview:communityNameLabel];
    
    y = 0;
    allNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    allNameLabel.numberOfLines = 2;
    allNameLabel.hidden = YES;
    allNameLabel.textColor = [UIColor blackColor];
    allNameLabel.font = [UIFont systemFontOfSize:14.0];
    allNameLabel.textAlignment = NSTextAlignmentCenter;
    [nameLabelView addSubview:allNameLabel];
    
    x = ScreenWidth - 40;
    y = 0;
    width = 40;
    height = 40;
    UIButton * communityNameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    communityNameBtn.frame = CGRectMake(x, y, width, height);
    [communityNameBtn setImage:[UIImage imageNamed:@"ic_close20"] forState:0];
    [communityNameBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
    [nameLabelView addSubview:communityNameBtn];
    
}

#pragma mark -- 取消显示集群名称
-(void)cancel
{
    nameLabelView.hidden = YES;
    if (![self IsHaveNetwork]) {
        upScrollerView.frame = CGRectMake(0, 0, upScrollerView.frame.size.width, upScrollerView.frame.size.height);
        mainContentScrollerView.frame = CGRectMake(0, upScrollerView.frame.origin.y + upScrollerView.frame.size.height, mainContentScrollerView.frame.size.width, mainContentScrollerView.frame.size.height + 40);
    }
    else
    {
        upScrollerView.frame = CGRectMake(0, 40, upScrollerView.frame.size.width, upScrollerView.frame.size.height);
        mainContentScrollerView.frame = CGRectMake(0, upScrollerView.frame.origin.y + upScrollerView.frame.size.height, mainContentScrollerView.frame.size.width, mainContentScrollerView.frame.size.height + 40);
    }
    
    NSMutableDictionary * HeightDict = [[NSMutableDictionary alloc]init];
    [HeightDict setValue:[NSString stringWithFormat:@"%f",mainContentScrollerView.frame.origin.y] forKey:@"height"];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"height" object:nil userInfo:HeightDict];
}



#pragma mark -- 取消显示集群名称

-(void)prepareCommunityData
{
    NSDictionary * communityInfo = [OpertionPlist readDataFromPlist];
    communityArray = [communityInfo objectForKey:COMMUNITYINFOFORKEY];
    if (communityArray.count > 0) {
        if (communityID == nil) {
//            communityID = [communityArray[0]objectForKey:@"communityid"];
//            singleton.communityId = communityID;
//            communityRole = [communityArray[0]objectForKey:@"role"];
            singleton.communityName = [communityArray[0]objectForKey:@"communityname"];
            communityNameLabel.text = [communityArray[0]objectForKey:@"communityname"];
        }
        else
        {
            for (NSDictionary * dict in communityArray) {
                if ([[dict objectForKey:@"communityid"] isEqualToString:communityID]) {
                    singleton.communityName = [dict objectForKey:@"communityname"];
                    communityNameLabel.text = [dict objectForKey:@"communityname"];
                    singleton.currentAreaCodeString = [dict objectForKey:@"areaCode"];
                }
            }
            
        }

        [self prepareUpScrollerView];
    }
    else
    {
        float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
        float ScreenHeight = self.view.frame.size.height;
        float x = 0;
        float y = 64;
        float width = ScreenWidth;
        float height = UI_SCREEN_HEIGHT - 49 - y;
        promtNoCommunityView = [[UIImageView alloc]initWithFrame:CGRectMake(x,y, width, height)];
        promtNoCommunityView.backgroundColor = RGBA(237, 238, 241, 1);
        promtNoCommunityView.userInteractionEnabled = YES;
//        AppDelegate * app = [UIApplication sharedApplication].delegate;
//        app.window = [UIApplication sharedApplication].keyWindow;
//        [app.window addSubview:promtNoCommunityView];
        [self.navigationController.view addSubview:promtNoCommunityView];
        UITapGestureRecognizer * imgViewTap  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(lookCommunityRole)];
        [promtNoCommunityView addGestureRecognizer:imgViewTap];
        
        x = 0;
        width = ScreenWidth;
        y = ScreenHeight / 2.0 - 20;
        height = 40;
        promtLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
        promtLabel.text = NSLocalizedString(@"addCommunityRefresh", nil);
        promtLabel.textColor = RGBA(143, 147, 148, 0.5);
        promtLabel.textAlignment = NSTextAlignmentCenter;
        promtLabel.font = [UIFont systemFontOfSize:16.0];
        promtLabel.numberOfLines = 2;
        [promtNoCommunityView addSubview:promtLabel];
        return;
    }
    
}


-(void)lookCommunityRole
{
    checkPower * power = [[checkPower alloc]init];
    [power getUserPower];
    power.powerBlock = ^(id data,id error)
    {
        if ([data objectForKey:@"data"] != nil)
        {
            [promtNoCommunityView removeFromSuperview];
            [self scrollViewDidEndScrollingAnimation:mainContentScrollerView];
            [self prepareUpScrollerView];
           NSDictionary * dataDict = [data objectForKey:@"data"];
            NSArray * communityInfoArray = [dataDict objectForKey:@"communities"];
            if (communityID == nil)
            {
                if (communityInfoArray.count > 0) {
                    singleton.communityName = [communityInfoArray[0] objectForKey:@"communityname"];
                    communityNameLabel.text = [communityInfoArray[0] objectForKey:@"communityname"];
                }
                
            }
            [bvc showVc:0];
        }
        else
        {
            [PromptInfoView showMessage:[error objectForKey:@"info"]];
        }
        
    };
}

#pragma mark === 断网或者突然来网络
-(void)netWorkBreak:(NSNotification *)not
{
    NetWorkBreakView.hidden = NO;
    float ScreenHeight = [UIScreen mainScreen].bounds.size.height;
    if(nameLabelView.hidden)
    {
        upScrollerView.frame = CGRectMake(upScrollerView.frame.origin.x,40, upScrollerView.frame.size.width, upScrollerView.frame.size.height);
        mainContentScrollerView.frame = CGRectMake(mainContentScrollerView.frame.origin.x, 80, mainContentScrollerView.frame.size.width, ScreenHeight - 80);
    }
    else
    {
        nameLabelView.frame = CGRectMake(0, 40, nameLabelView.frame.size.width, nameLabelView.frame.size.height);
        [self.view addSubview:nameLabelView];
        [self.view addSubview:allBackImgView];
        upScrollerView.frame = CGRectMake(upScrollerView.frame.origin.x,80, upScrollerView.frame.size.width, upScrollerView.frame.size.height);
        mainContentScrollerView.frame = CGRectMake(mainContentScrollerView.frame.origin.x, 120, mainContentScrollerView.frame.size.width, ScreenHeight - 120);
    }
    NSMutableDictionary * HeightDict = [[NSMutableDictionary alloc]init];
    [HeightDict setValue:[NSString stringWithFormat:@"%f",mainContentScrollerView.frame.origin.y] forKey:@"height"];
    [[NSNotificationCenter defaultCenter]postNotificationName:ChangeHeight object:nil userInfo:HeightDict];
}

-(void)JoinNetWork:(NSNotification *)not
{
    NetWorkBreakView.hidden = YES;
    float ScreenHeight = [UIScreen mainScreen].bounds.size.height;
    if (nameLabelView.hidden) {
        nameLabelView.frame = CGRectMake(0, 0, nameLabelView.frame.size.width, nameLabelView.frame.size.height);
        upScrollerView.frame = CGRectMake(upScrollerView.frame.origin.x,0, upScrollerView.frame.size.width, upScrollerView.frame.size.height);
        mainContentScrollerView.frame = CGRectMake(mainContentScrollerView.frame.origin.x, 40, mainContentScrollerView.frame.size.width, ScreenHeight - 40 - 49);
    }
    else
    {
        nameLabelView.frame = CGRectMake(0, 0, nameLabelView.frame.size.width, nameLabelView.frame.size.height);
        upScrollerView.frame = CGRectMake(upScrollerView.frame.origin.x,40, upScrollerView.frame.size.width, upScrollerView.frame.size.height);
        mainContentScrollerView.frame = CGRectMake(mainContentScrollerView.frame.origin.x, 80, mainContentScrollerView.frame.size.width, ScreenHeight - 80);
    }
    NSMutableDictionary * HeightDict = [[NSMutableDictionary alloc]init];
    [HeightDict setValue:[NSString stringWithFormat:@"%f",mainContentScrollerView.frame.origin.y] forKey:@"height"];
    [[NSNotificationCenter defaultCenter]postNotificationName:ChangeHeight object:nil userInfo:HeightDict];
}

-(void)changeHeight
{
    if (nameLabelView.hidden) {
        nameLabelView.hidden = NO;
        upScrollerView.frame = CGRectMake(0, nameLabelView.frame.origin.y + nameLabelView.frame.size.height, upScrollerView.frame.size.width, upScrollerView.frame.size.height);
        mainContentScrollerView.frame = CGRectMake(0, upScrollerView.frame.origin.y + upScrollerView.frame.size.height, mainContentScrollerView.frame.size.width, mainContentScrollerView.frame.size.height - 40);
        NSMutableDictionary * HeightDict = [[NSMutableDictionary alloc]init];
        [HeightDict setValue:[NSString stringWithFormat:@"%f",mainContentScrollerView.frame.origin.y] forKey:@"height"];
        [[NSNotificationCenter defaultCenter]postNotificationName:ChangeHeight object:nil userInfo:HeightDict];
    }
}

-(void)prepareUpScrollerView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    float x = 0;
    float y = nameLabelView.frame.size.height + nameLabelView.frame.origin.y;
    float width = ScreenWidth;
    float height = 40;
    
    upScrollerView = [[UIScrollView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    upScrollerView.pagingEnabled = YES;
    upScrollerView.showsHorizontalScrollIndicator = YES;
    upScrollerView.bounces = NO;
    upScrollerView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:upScrollerView];
    
    nameArray = @[NSLocalizedString(@"staff", nil),NSLocalizedString(@"guest", nil),NSLocalizedString(@"property", nil)];
    int count = (int)nameArray.count;
    width = ScreenWidth / 3.0;
    x = 0;
    y = 10;
    height = 20;
    for (int i = 0 ; i < count; i ++) {
        upScrollerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        upScrollerBtn.frame = CGRectMake(x, y, width, height);
        [upScrollerBtn setTitle:nameArray[i] forState:0];
        [upScrollerBtn setTitleColor:[UIColor blackColor] forState:0];
        upScrollerBtn.titleLabel.font = [UIFont systemFontOfSize:18.0];
        upScrollerBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
        [upScrollerBtn addTarget:self action:@selector(moveBtn:) forControlEvents:UIControlEventTouchUpInside];
        upScrollerBtn.tag = 500 + i;
        [upScrollerView addSubview:upScrollerBtn];
        x += width;
    }
    
    x = 0;
    width = ScreenWidth / 3.0;
    height = 3;
    y = 36;
    indexBackGroundView = [[UIView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    indexBackGroundView.backgroundColor = RGBA(125, 194, 52, 1);
    [upScrollerView addSubview:indexBackGroundView];
    
    UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 39, ScreenWidth, 1)];
    lineView.backgroundColor = RGBA(193, 193, 193, 1);
    [upScrollerView addSubview:lineView];
}

#pragma mark -- 点击按钮来移动scrollverview
-(void)moveBtn:(UIButton *)button
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    CGRect newFrame;
    newFrame = indexBackGroundView.frame;
    if (button.tag == 500) {
        newFrame.origin.x = 0;
    }
    else if (button.tag == 501) {
        newFrame.origin.x = ScreenWidth / 3.0;
    }
    else if (button.tag == 502) {
        newFrame.origin.x = 2 * ScreenWidth / 3.0;
    }
    if (button.tag - 500 == singleton.managementIndex) {
        return;
    }else
    {
        bvc = self.childViewControllers[singleton.managementIndex];
        [bvc hiddenVc:singleton.managementIndex];
    }
    [UIView animateWithDuration:0.5 animations:^{
        indexBackGroundView.frame = newFrame;
        mainContentScrollerView.contentOffset = CGPointMake([UIScreen mainScreen].bounds.size.width * (button.tag - 500), 0);
    } completion:^(BOOL finished) {
        nowContentOffX = (int)button.tag - 500;
        [self scrollViewDidEndScrollingAnimation:mainContentScrollerView];
    }];
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    mainContentScrollerView.contentOffset = scrollView.contentOffset;
    int countTag = scrollView.contentOffset.x / ScreenWidth;
    nowContentOffX = countTag;
    [self ScrollerViewMoveAddBtnMove:countTag];
}



-(void)ScrollerViewMoveAddBtnMove:(int)count
{
    CGRect newFrame;
    newFrame = indexBackGroundView.frame;
    newFrame.origin.x = [UIScreen mainScreen].bounds.size.width /3.0* count;
    [UIView animateWithDuration:0.5 animations:^{
        indexBackGroundView.frame = newFrame;
    } completion:^(BOOL finished) {
        
    }];
    
}

#pragma mark == 操作提示
-(void)tellUserUseAppPromtView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    float ScreenHeight = [UIScreen mainScreen].bounds.size.height;
    float x = 0;
    float y = 0;
    float width = ScreenWidth;
    float height = ScreenHeight;
    UIImageView * promtBackView = [[UIImageView alloc]initWithFrame:CGRectMake(x,y, width, height)];
    promtBackView.backgroundColor = RGBA(0, 0, 0, 0.5);
    promtBackView.userInteractionEnabled = YES;
    AppDelegate * app = [UIApplication sharedApplication].delegate;
    app.window = [UIApplication sharedApplication].keyWindow;
    [app.window addSubview:promtBackView];

    UITapGestureRecognizer * imgViewTap  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imgViewClick:)];
    [promtBackView addGestureRecognizer:imgViewTap];
    
    x = 0;
    width = ScreenWidth;
    height = 318.0 / 640 * ScreenWidth;
    y = ScreenHeight - 45 - height;
    quickImgView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    quickImgView.image = [UIImage imageNamed:NSLocalizedString(@"quickCard", nil)];
    [promtBackView addSubview:quickImgView];
    
    
    x = -5;
    width = ScreenWidth;
    height = 347.0 / 640 * width;
    y = 30;
    changeCommunityImgView  = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    changeCommunityImgView.image = [UIImage imageNamed:NSLocalizedString(@"switchCommunityPromt", nil)];
    [promtBackView addSubview:changeCommunityImgView];
    NSUserDefaults * userInfo = [NSUserDefaults standardUserDefaults];
    if ([[userInfo objectForKey:@"middle"]isEqualToString:@"yes"]) {
        changeCommunityImgView.hidden = YES;
    }
    else
    {
        quickImgView.hidden = YES;
    }
}

-(void)imgViewClick:(UITapGestureRecognizer *)tap
{
    NSUserDefaults * userInfo = [NSUserDefaults standardUserDefaults];
    if ([[userInfo objectForKey:@"middle"]isEqualToString:@"yes"]) {
        quickImgView.hidden = YES;
        changeCommunityImgView.hidden = NO;
        [userInfo setValue:@"no" forKey:@"middle"];
        [userInfo synchronize];
    }
    else
    {
        UIImageView * imageView = (UIImageView *)tap.view;
        [imageView removeFromSuperview];
        [[NSUserDefaults standardUserDefaults]setValue:@"no" forKey:@"changeCommunity"];
    }
    
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
